package com.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;

import java.util.Arrays;

public class MyAspect {

    //前置通知方法
    public void a(){
        System.out.println("前置代码增强.....");
    }
    //后置通知方法
    public void b(){
        System.out.println("后置代码增强.....");
    }

    //环绕通知方法
    public Object c(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("环绕通知");
        //joinPoint切入点  可以获取当执行方法相关内容
        Object[] args = joinPoint.getArgs();//获取当期切点参数
        Object proceed = joinPoint.proceed(args);//执行原方法
        System.out.println("环绕通知"+ Arrays.toString(args));
        return proceed;
    }
    //异常通知
    public void d(Exception e1) {
        System.out.println("异常通知"+e1);
    }

    //返回通知
    public void e(JoinPoint joinPoint, Object result) throws Throwable {
        System.out.println("返回通知");
        System.out.println(Arrays.toString(joinPoint.getArgs()));
        System.out.println(result);
    }
}
